#! /usr/bin/env python
# -*- coding: utf8 -*-

import zope.interface

import base

class upTree(object):
    zope.interface.implements(base.IAlgorithm)
    name = "upTree"

    def __init__(self, node):
        pass

    def __call__(self, node, parentMap, root):
        if node not in parentMap:
            return

        keys = node[:]


        if node not in parentMap[node] or len(keys) == 0:
            return
        parentMap[node].remove(node)

        for i in keys:
            parentMap[i] = parentMap[node]
            parentMap[i].append(i)

        parentMap.pop(node)
        return -1

__plugins__ = (upTree, )
